<!-- ActionDialog.vue -->
<template>
  <el-dialog
    title="商品通知"
    :visible.sync="visible"
    width="600px"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    @close="handleClose"
  >
    <el-card style="margin-bottom: 20px;">
      编号：{{ spu }}
    </el-card>
    <el-row>
      <el-col :span="6" style="text-align: center">
        <el-button type="primary" @click="handleAction('goods.add')">商品新增通知</el-button>
      </el-col>
      <el-col :span="6" style="text-align: center">
        <el-button type="success" @click="handleAction('goods.update')">商品更新通知</el-button>
      </el-col>
      <el-col :span="6" style="text-align: center">
        <el-button type="warning" @click="handleAction('goods.shelve')">商品上架通知</el-button>
      </el-col>
      <el-col :span="6" style="text-align: center">
        <el-button type="danger" @click="handleAction('goods.unshelve')">商品下架通知</el-button>
      </el-col>
    </el-row>
    <el-row style="margin-top: 20px;">
      <el-col :span="6" style="text-align: center">
        <el-button type="info" @click="handleAction('goods.price')">商品价格通知</el-button>
      </el-col>
      <el-col :span="6" style="text-align: center">
        <el-button type="primary" plain @click="handleAction('goods.stock')">商品库存通知</el-button>
      </el-col>
    </el-row>
  </el-dialog>
</template>

<script>
import { triggerGoods } from '@/api/externalGoods'

export default {
  props: {
    visible: {
      type: Boolean,
      required: true
    },
    spu: {
      type: String,
      required: true
    }
  },
  methods: {
    handleClose(done) {
      this.$emit('close')
    },
    handleAction(action) {
      triggerGoods({
        goods_spu: this.spu,
        type: action
      }).then(res => {
        console.log(res)
        if (res.code === 10000) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.handleClose()
        }
      })
    }
  }
}
</script>

<style scoped>
/* 可根据需要添加样式 */
</style>
